import { get } from 'lodash'
export default {
  methods: {
    createSnapshot () {

    },
    async getSnapshot (data, only = true) {
      const { id } = data
      const { list } = this.$interface.snapshots
      const params = {

        resourceId: id
      }
      const { data: response } = await list(params)
      if (response.code !== 0) {
        throw get(response, 'msg', '')
      }

      const files = response.data || []
      if (only && files.length) {
        return [files[files.length - 1]]
      }
      return files
    },
    async depositSnapshot (filePath, data) {
      const { resourceType, id } = data
      const { insert } = this.$interface.snapshots
      const params = {
        fileType: 1,
        filePath,
        resourceType,
        resourceId: id
      }
      const { data: response } = await insert(params)
      if (response.code !== 0) {
        throw get(response, 'msg', '')
      }
    }
  }
}
